<HTML>
<HEAD>
<TITLE>
IndiceArbolB.cpp
</TITLE>
</HEAD>
<BODY>
<PRE>
<font color="green">/*
 * IndiceArbolB.cpp
 *
 *  Created on: 15/10/2009
 *      Author: andres
 */</font>

<font color="blue">#define</font> CANT_CLAVES <font color="maroon">5</font>;

<font color="blue">#include</font> <font color="maroon">"IndiceArbolB.h"</font>

IndiceArbolB<font color="black">:</font><font color="black">:</font>IndiceArbolB<font color="black">(</font>PrimaryKey <font color="black">*</font>primaryKey<font color="black">)</font> <font color="blue">throw</font><font color="black">(</font>IndexException<font color="black">)</font> <font color="black">:</font> EstrategiaIndice<font color="black">(</font> primaryKey<font color="black">)</font>
<font color="black">{</font>
    raiz<font color="black">=</font><font color="blue">new</font> NodoArbolB<font color="black">(</font><font color="maroon">5</font><font color="black">)</font>;
<font color="black">}</font>

IndiceArbolB<font color="black">:</font><font color="black">:</font>IndiceArbolB<font color="black">(</font>PrimaryKey <font color="black">*</font>PrimaryKey, SecondaryKey <font color="black">*</font>secondaryKey, EstrategiaIndice <font color="black">*</font>indicePrimario<font color="black">)</font> <font color="blue">throw</font><font color="black">(</font>IndexException<font color="black">)</font> <font color="black">:</font>EstrategiaIndice<font color="black">(</font> PrimaryKey, secondaryKey, indicePrimario<font color="black">)</font>
<font color="black">{</font>
    raiz<font color="black">=</font><font color="blue">new</font> NodoArbolB<font color="black">(</font><font color="maroon">5</font><font color="black">)</font>;
<font color="black">}</font>



<font color="blue">void</font> IndiceArbolB<font color="black">:</font><font color="black">:</font>Cargar<font color="black">(</font><font color="blue">char</font> <font color="black">*</font>datoSerializadoACargar, <font color="blue">unsigned</font> <font color="blue">int</font> id<font color="black">)</font> <font color="blue">throw</font><font color="black">(</font>IndexException<font color="black">)</font>
<font color="black">{</font>
    <font color="blue">if</font><font color="black">(</font> raiz<font color="black">-</font><font color="black">&#62;</font>nodos.size<font color="black">(</font><font color="black">)</font> <font color="black">&#62;</font><font color="black">=</font> <font color="maroon">5</font><font color="black">)</font>
    <font color="black">{</font>
        <font color="green">//cuando se desborda la raiz se esta por duplicar le agrego otra raiz</font>
        NodoArbolB<font color="black">*</font> aux<font color="black">=</font><font color="blue">new</font> NodoArbolB<font color="black">(</font><font color="maroon">5</font><font color="black">)</font>;
        aux<font color="black">-</font><font color="black">&#62;</font>nodos.push_back<font color="black">(</font>raiz<font color="black">)</font>;
        Clave<font color="black">*</font> clave;
        raiz<font color="black">-</font><font color="black">&#62;</font>MayorClave<font color="black">(</font>clave<font color="black">)</font>;
        aux<font color="black">-</font><font color="black">&#62;</font>claves.push_back<font color="black">(</font>clave<font color="black">)</font>;
        raiz<font color="black">=</font>aux;
    <font color="black">}</font>
    raiz<font color="black">-</font><font color="black">&#62;</font>Ingresar<font color="black">(</font>CargarInformacion<font color="black">(</font>datoSerializadoACargar, id<font color="black">)</font><font color="black">)</font>;

<font color="black">}</font>



<font color="blue">void</font> IndiceArbolB<font color="black">:</font><font color="black">:</font>Eliminar<font color="black">(</font><font color="blue">char</font> <font color="black">*</font>DatoSerializadoAEliminar<font color="black">)</font>
<font color="black">{</font>
    raiz<font color="black">-</font><font color="black">&#62;</font>Quitar<font color="black">(</font>CargarInformacion<font color="black">(</font>DatoSerializadoAEliminar, <font color="maroon">0</font><font color="black">)</font><font color="black">)</font>;
<font color="black">}</font>



std<font color="black">:</font><font color="black">:</font>vector<font color="black">&#60;</font><font color="blue">unsigned</font> <font color="blue">int</font><font color="black">&#62;</font> IndiceArbolB<font color="black">:</font><font color="black">:</font>Buscar<font color="black">(</font>std<font color="black">:</font><font color="black">:</font>string claveABuscar<font color="black">)</font>
<font color="black">{</font>
    Clave<font color="black">*</font> clave;

    <font color="blue">if</font><font color="black">(</font><font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>EsIndicePrimario<font color="black">(</font><font color="black">)</font><font color="black">)</font>
        clave<font color="black">=</font> <font color="blue">new</font> Clave<font color="black">(</font><font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>primaryKey<font color="black">-</font><font color="black">&#62;</font>GetTamanio<font color="black">(</font><font color="black">)</font><font color="black">)</font>;
    <font color="blue">else</font>
        clave<font color="black">=</font> <font color="blue">new</font> Clave<font color="black">(</font><font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>secondaryKey<font color="black">-</font><font color="black">&#62;</font>GetTamanio<font color="black">(</font><font color="black">)</font><font color="black">)</font>;

    <font color="blue">char</font><font color="black">*</font> buscar<font color="black">=</font><font color="black">(</font><font color="blue">char</font><font color="black">*</font><font color="black">)</font>malloc<font color="black">(</font>claveABuscar.size<font color="black">(</font><font color="black">)</font><font color="black">)</font>;
    memcpy<font color="black">(</font>buscar,claveABuscar.c_str<font color="black">(</font><font color="black">)</font>,claveABuscar.size<font color="black">(</font><font color="black">)</font><font color="black">)</font>;
    clave<font color="black">-</font><font color="black">&#62;</font>Cargar<font color="black">(</font>buscar<font color="black">)</font>;
    vector<font color="black">&#60;</font>Informacion<font color="black">*</font><font color="black">&#62;</font> info<font color="black">=</font>raiz<font color="black">-</font><font color="black">&#62;</font>Buscar<font color="black">(</font>clave<font color="black">)</font>;

    vector<font color="black">&#60;</font><font color="blue">unsigned</font> <font color="blue">int</font><font color="black">&#62;</font> claves;
    <font color="blue">if</font><font color="black">(</font><font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>EsIndicePrimario<font color="black">(</font><font color="black">)</font><font color="black">)</font>
        <font color="blue">for</font><font color="black">(</font><font color="blue">int</font> i<font color="black">=</font><font color="maroon">0</font>; <font color="black">(</font><font color="blue">unsigned</font> <font color="blue">int</font><font color="black">)</font>i<font color="black">&#60;</font>info.size<font color="black">(</font><font color="black">)</font>; i<font color="black">+</font><font color="black">+</font><font color="black">)</font>
        <font color="black">{</font>
            claves.push_back<font color="black">(</font>info<font color="black">[</font>i<font color="black">]</font><font color="black">-</font><font color="black">&#62;</font>GetID<font color="black">(</font><font color="black">)</font><font color="black">)</font>;
        <font color="black">}</font>
    <font color="blue">else</font>
    <font color="black">{</font>
        <font color="blue">for</font><font color="black">(</font><font color="blue">int</font> i<font color="black">=</font><font color="maroon">0</font>; <font color="black">(</font><font color="blue">unsigned</font> <font color="blue">int</font><font color="black">)</font>i<font color="black">&#60;</font>info.size<font color="black">(</font><font color="black">)</font>; i<font color="black">+</font><font color="black">+</font><font color="black">)</font>
        <font color="black">{</font>
            std<font color="black">:</font><font color="black">:</font>string nombre<font color="black">(</font>info<font color="black">[</font>i<font color="black">]</font><font color="black">-</font><font color="black">&#62;</font>GetPrimaryKey<font color="black">(</font><font color="black">)</font><font color="black">)</font>;
            claves.push_back<font color="black">(</font><font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>indicePrimario<font color="black">-</font><font color="black">&#62;</font>Buscar<font color="black">(</font>nombre<font color="black">)</font><font color="black">[</font><font color="maroon">0</font><font color="black">]</font><font color="black">)</font>;
        <font color="black">}</font>
    <font color="black">}</font>

    <font color="blue">return</font> claves;

<font color="black">}</font>



<font color="blue">void</font> IndiceArbolB<font color="black">:</font><font color="black">:</font>Modificar<font color="black">(</font><font color="blue">char</font> <font color="black">*</font>DatoSerializadoSinModificar, <font color="blue">char</font> <font color="black">*</font>DatoSerializadoModificado, <font color="blue">unsigned</font> <font color="blue">int</font> idModificado<font color="black">)</font>
<font color="black">{</font>
    Eliminar<font color="black">(</font>DatoSerializadoSinModificar<font color="black">)</font>;
    Cargar<font color="black">(</font>DatoSerializadoModificado, idModificado<font color="black">)</font>;
<font color="black">}</font>





IndiceArbolB<font color="black">:</font><font color="black">:</font>~IndiceArbolB<font color="black">(</font><font color="black">)</font>
<font color="black">{</font>
    <font color="blue">delete</font> raiz;
<font color="black">}</font>



Informacion <font color="black">*</font>IndiceArbolB<font color="black">:</font><font color="black">:</font>CargarInformacion<font color="black">(</font><font color="blue">char</font> <font color="black">*</font>datoSerializadoACargar, <font color="blue">unsigned</font> <font color="blue">int</font> id<font color="black">)</font>
<font color="black">{</font>
    Informacion<font color="black">*</font> informacion;

    <font color="blue">if</font><font color="black">(</font><font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>EsIndicePrimario<font color="black">(</font><font color="black">)</font><font color="black">)</font>
    <font color="black">{</font>
        informacion<font color="black">=</font> <font color="blue">new</font> Informacion<font color="black">(</font><font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>primaryKey<font color="black">-</font><font color="black">&#62;</font>GetTamanio<font color="black">(</font><font color="black">)</font>,<font color="maroon">4</font><font color="black">)</font>;
    <font color="black">}</font>
    <font color="blue">else</font>
    <font color="black">{</font>
        informacion<font color="black">=</font> <font color="blue">new</font> Informacion<font color="black">(</font><font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>secondaryKey<font color="black">-</font><font color="black">&#62;</font>GetTamanio<font color="black">(</font><font color="black">)</font>,<font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>primaryKey<font color="black">-</font><font color="black">&#62;</font>GetTamanio<font color="black">(</font><font color="black">)</font><font color="black">)</font>;
    <font color="black">}</font>

    DatoIndice dato<font color="black">(</font><font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>secondaryKey,<font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>primaryKey<font color="black">)</font>;
    informacion<font color="black">-</font><font color="black">&#62;</font>Cargar<font color="black">(</font>dato.GetDato<font color="black">(</font>datoSerializadoACargar, id<font color="black">)</font><font color="black">)</font>;

    <font color="blue">return</font> informacion;

<font color="black">}</font>






</PRE>
</BODY>
</HTML>
